<?php
use DoctrineExtensions\Paginate\Paginate;

class Default_AboutController extends Zend_Controller_Action
{
    protected $_em;
    protected $_repo;
    protected $_flash;
    
    public function init()
    {       
        $this->_em = Zend_Registry::get('doctrine');        
        $this->_flash = $this->_helper->getHelper('FlashMessenger'); 

        $this->view->headLink()->appendStylesheet("/css/default/career.css");
    }  
      
    public function indexAction()
    {
        $db_page = new Default_Model_DbTable_Page();
        $this->view->content =  $db_page->getdetailpage(1);
    }    
    
    public function partnerAction()
    {
        $this->view->headLink()->appendStylesheet("/css/default/partner.css");
        //$this->_repo = $this->_em->getRepository('Entities\HaePartner');
        //$this->_initPager();        
        //$this->view->rows = $this->_repo->getPage($this->view->pageNum, $this->view->pageSize);
//         // Variables       
//         $page = $this->getRequest()->getParam("page",1);
        
//         $db_partner = new Default_Model_DbTable_Partner();
//         $adaptor = $db_partner->getListPartner();    
       
//         $paginator = new Zend_Paginator($adaptor);
//         $paginator->setItemCountPerPage(1);
//         $paginator->setCurrentPageNumber($page);   
                
//         //Values
//         $this->view->partners = $paginator;   
      
        
      //  $dql = $dql->select('p')->from('\Entities\HaePartner', 'p');
       // $query = $this->_em->createQuery("SELECT e FROM $this->_entityClassName e");
        
       // $count = Paginate::getTotalQueryResults($query); // Step 1
       // $paginateQuery = Paginate::getPaginateQuery($query, 0, 2); // Step 2 and 3
      //  $result = $paginateQuery->getResult();
        //var_dump($result);
        //$test = new Entities\HaePartner;       
        //$test->setName('paul');
        //$this->_em->persist($test);
        //$this->_em->flush();
        //$this->view->result = $result;
      	//$result = $this->_em->getRepository('Entities\HaePartner')->findAll()->slice(2, 0);
      	//$result = $this->_em->getRepository('Entities\HaePartner')->getPage();
      	//$result = $this->_em->getRepository('Entities\HaePartner')->findOneByName('paul');
        //var_dump($result);

        
        //var_dump($doc);
       //var_dump($em);
       
//         $result = $this->_em->getRepository('Default_Model_Account')->findOneByEmail('smith');
// 		var_dump($result);   
//         $result2 = $this->_em->getRepository('Default_Model_Account')->findOneByEmail('jb.beauchamp@starseed.fr');
// 		var_dump($result2);  
// 		//$result2->setEmail('jb.beauchamp@starseed.fr');

// 		echo $result2->getEmail() . "\n";
		
// 		//$doc->_em->flush();
		
// 		// 2 snd method
// 		//$em = Zend_Registry::get('em');
				
// 		$account = $this->_em->find('Default_Model_Account', 2);
		
// 		echo "Name : " . $account->getName() . "\n";
		
      	//$group = new Default_Model_Group();
       // $group = $em->find('Default_Model_Group', 1);
//         var_dump($group);
       //  $paul = new Entity\User;
//         $paul->setUsername('paul');
//         $paul->setEmail('paul.seiffert@example.com');
//         $em->persist($paul);
        
//         $group->addMember($paul);
        
//         $em->flush();
        
//         $account = $em->getRepository('Entities\Account')->findOneByUsername('smith');
//         $game = $em->getRepository('Entities\Game')->findOneByName('Fallout');
//         $account->getGames()->add($game);
//         $em->persist($account);
//         $em->flush();
        
        
       
        $this->_repo = $this->_em->getRepository('Entities\HaePartner');   
        $this->_initPager();
        $this->view->rows = $this->_repo->getPage($this->view->pageNum, $this->view->pageSize);
        
        //$o = new \Services\PartnerService($this->_em);        
        //$this->view->rows = $o->getPartners();
       
        //var_dump($records);
        
            
    } 
     
    /********************************************************************************
     CAREER 
    *********************************************************************************/

    public function careerAction()
    {
        
        
        $this->_repo = $this->_em->getRepository('Entities\HaeCareer');
        $this->_initPager();
        
        $this->view->rows = $this->_repo->getPage($this->view->pageNum, $this->view->pageSize);
       // $this->view->rows = $this->_repo->getAll();
               
    }    
    
    public function detailcareerAction()
    {
        
    	$id = $this->_getParam('id', 0);
    
    	
    	$this->_repo = $this->_em->getRepository('Entities\HaeCareer');
    	$data = $this->_repo->findOneById($id);
    
    	if (!$data)
    	{
    		throw new Exception('Unable to find the data.');
    	}

    	//Create an object if we want to use it in view for some operations
    	$this->view->data = $data;
    	
    }
    
    
    protected function _initPager() 
    {
    	$page = $this->getRequest()->getParam('page');
    	$page = $page ? $page : 0;
    
    	$size = $this->getRequest()->getParam('size');
    	$size = $size ? $size : 2;
    
    	$this->view->pageNum =  $page;
    	$this->view->pageSize = $size;
    
    	$this->view->count = $this->_repo->getCount();
    	$this->view->numPages = ($numPages = $this->_repo->getPageCount($size));
    
    	$pagerRadius = 3;
    
    	$lbound = $page - $pagerRadius;
    	$rbound = $page + $pagerRadius;
    
    	$this->view->lBound = $lbound > 0 ? $lbound : 0;
    	$this->view->rBound = $rbound <= $numPages ? $rbound : $numPages;
    
    	$this->view->lNum = $page - 1 ? $page - 1 : 1;
    	$this->view->rNum = $page + 1 <= $numPages ? $page + 1 : $numPages;
    }
}
